import Common from './common_fun.js'

// 设置键盘转换
const com_change_btn = document.getElementById('c-change')
const sci_change_btn = document.getElementById('s-change')
//几个特殊的健
const com_AC = document.getElementById('c-ac')
const sci_AC = document.getElementById('s-ac')
const com_del = document.getElementById('c-del')
const sci_del = document.getElementById('s-del')
const com_equal = document.getElementById('c-equal')
const sci_equal = document.getElementById('s-equal')
const sci_2nd = document.getElementById('s-2nd')
const sci_sin = document.getElementById('s-sin')
const sci_cos = document.getElementById('s-cos')
const sci_tan = document.getElementById('s-tan')
const sci_deg =  document.getElementById('s-deg')
const sci_pow = document.getElementById('s-power')
const sci_fact = document.getElementById('s-fact')
const sci_back = document.getElementById('s-back')

//标签文本即为要显示的内容的键
const text_key = document.getElementsByClassName('text-key')

com_change_btn.onclick = function(){
    document.getElementById('board-common').style.display = 'none'
    document.getElementById('board-sci').style.display = 'block'
    document.getElementById('space-padding').className = 'space-padding-sci'

}
sci_change_btn.onclick = function(){
    document.getElementById('board-sci').style.display = 'none'
    document.getElementById('board-common').style.display = 'block'
    document.getElementById('space-padding').className = 'space-padding-common'
}
com_AC.onclick = sci_AC.onclick = function(){
    Common.setProgress('')
    Common.setResult('0')
} 
com_del.onclick = sci_del.onclick = function(){
    const pro = Common.getProgress()
    Common.setProgress(pro!==''?pro.substring(0,pro.length-1):pro)
}

com_equal.onclick =  function(){
    const p = Common.getProgress()
    const r = Common.calcCommon(p)
    Common.setResult(r)
}

sci_equal.onclick =  function(){
    const p = Common.getProgress()
    const r = Common.calcSci(p)
    Common.setResult(r)
}

sci_2nd.onclick = function(){
    if(sci_sin.innerHTML.trim()==='sin'){
        sci_sin.innerHTML = 'sin<sup>-1</sup>'
        sci_cos.innerHTML = 'cos<sup>-1</sup>'
        sci_tan.innerHTML = 'tan<sup>-1</sup>'
    }else{
        sci_sin.innerHTML = 'sin'
        sci_cos.innerHTML = 'cos'
        sci_tan.innerHTML = 'tan'
    }
}
sci_deg.onclick = function(){
    console.error('没搞懂这个键的功能，角度和弧度的转换？')
}
sci_pow.onclick = function(){
    Common.setProgress(Common.getProgress()+'^')
}
sci_fact.onclick = function(){
    Common.setProgress(Common.getProgress()+'!')
}
sci_back.onclick = function(){
    Common.setProgress(Common.getProgress()+'^(-1)')
}

//绑定普通健的点击回调
for(let k of text_key){
    k.onclick = Common.appendText(k)
}
